import { login } from "@/api/user";
import { defineStore } from "pinia";
const useUserStore = defineStore('userStore',{
    state:()=>{
        return {
            userInfo:localStorage.getItem('userinfo')?JSON.parse(localStorage.getItem('userinfo')):'',
            token:localStorage.getItem('token')?localStorage.getItem('token'):''
        }
    },
    actions:{
        //登录
        async typeLogins(data) {
           let result = await login(data);
           if(result.code == 200) {
            this.userInfo = result.data?.info
            localStorage.setItem('userinfo',JSON.stringify(result.data?.info))
            this.token = result.data?.token
            localStorage.setItem('token',result.data?.token)
           
           }
        },
        //退出登录
        logout() {
            this.userInfo = ''
            this.token = ''
            localStorage.removeItem('userinfo')
            localStorage.removeItem('token')
        }
    },
    getters:{
        
    }
})


export default useUserStore